<template>
  <div class="navigation">
    <div class="header">
      <div class="content back">
        <span style="float: left;">
          欢迎您
          <span is="router-link" to="/login" tag="span">点击登录</span>
        </span>

        <p>萌 宠 找 货 , 专 业 的 宠 物 物 品 平 台 , 为 你 的 萌 宠 找 一 个 最 好 的 宠 爱 ! ! !</p>
        <ul class="nav">
          <li is="router-link" to="/login" tag="li"><span>登录</span><span>|</span></li>
          <li is="router-link" to="/logon" tag="li"><span>注册</span><span>|</span></li>
          <li is="router-link" to="/cart" tag="li"><span>我的订单</span><span>|</span></li>
          <li>
            <el-dropdown>
              <span class="el-dropdown-link">
                请登录<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item><router-link to="/mine" tag="span">个人中心</router-link></el-dropdown-item>
                <el-dropdown-item><router-link to="/cart" tag="span">订单中心</router-link></el-dropdown-item>
                <el-dropdown-item>退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            <span></span>
          </li>
        </ul>
      </div>
    </div>
    <div class="content">
      <div class="main-nav">
        <a is="router-link" to="/home"><img src="@/image/logo.png" alt=""></a>
        <div class="main-input">
          <el-input style="width: 500px" v-model="input" placeholder="请输入想要搜索的物品"></el-input>
          <el-button type="primary" @click="search">搜索</el-button>
        </div>
        <div class="search-car">
          <div class="shop-car" is="router-link" to="/cart" tag="div">
            <span>购物袋</span>
            <img src="/img/car.png" alt="">
            <div class="shop-num" id="header-num">0</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex'

export default {
  name: 'navigation',
  data () {
    return {
      input: ''
    }
  },
  methods: {
    ...mapActions(['addSearch']),
    search () {
      if (this.input.trim().length === 0) {
        return
      }
      this.addSearch(this.input)
      this.$router.push({
        path: '/list',
        query: {
          word: this.input
        }
      })
      this.input = ''
    }
  }
}
</script>

<style lang="scss" scoped>
.header{
  height: 36px;
  background-color: rgb(51,51,51);
  >.back{
    height: 36px;
    width: 1170px;
    margin: auto;
    background-color: rgb(51,51,51);
    overflow: hidden;
  }
  >.content{
    width: 1170px;
    margin: auto;
    position: relative;
    overflow: hidden;
    >span,a{
      line-height: 36px;
      font-size: 12px;
      color: #ebe5e5;
      >img{
        margin-right: 5px;
      }
      >span{
        font-size: 13px;
        margin-left: 10px;
        cursor: pointer;
        color: #dfd1d1;
      }
    }
    >p{
      position: absolute;
      line-height: 36px;
      font-size: 12px;
      color: #cecaca;
      left: 335px;
    }
    >.nav{
      float: right;
      >li{
        float: left;
        line-height: 36px;
        font-size: 12px;
        color: #ffffff;
        >:last-child{
          padding: 0 12px;
        }
        >:first-child{
          cursor: pointer;
        }
      }
    }
  }
}
.content{
  width: 1170px;
  margin: auto;
  position: relative;
}
.main-nav{
  width: 1170px;
  height: 109px;
  position: relative;
  >a{
    position: absolute;
    display: inline-block;
    left: 56px;
    top: 15px;
    >img{
      width: 70px;
    }
  }
  >.main-input{
    position: absolute;
    top: 30px;
    left: 280px;
  }
  >.search-car{
    width: 90px;
    display: inline-block;
    height: 36px;
    top: 30px;
    right: 17px;
    position: absolute;
    >.shop-car{
      display: inline-block;
      float: right;
      cursor: pointer;
      height: 22px;
      width: 80px;
      padding: 7px 12px;
      border: 1px solid #D9D9D9;
      border-radius: 6px;
      font-size: 14px;
      >img{
        margin: 0 8px;
      }
      >.shop-num{
        display: inline-block;
        width: 22px;
        height: 22px;
        background-color: red;
        border-radius: 10px;
        text-align: center;
        line-height: 22px;
        color: white;
      }
    }
  }
}
.el-dropdown-link {
  cursor: pointer;
  color: #fff;
  font-size: 12px;
}
.el-icon-arrow-down {
  font-size: 12px;
}
</style>
